//
//  Create.swift
//  MZTool_Example
//
//  Created by gby on 2023/3/2.
//  Copyright © 2023 CocoaPods. All rights reserved.
//

import UIKit
import MZTool
import Then

class SuqareBackGroundReusableView: UICollectionReusableView {
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = .gray
    }

}



class Create: BaseViewVCtrl, UICollectionViewDelegate, UICollectionViewDataSource, MZFlowLayout_BackgroundDelegate {
    
    
    private lazy var colflow = MZFlowLayout_Background.init().then{
        $0.minimumLineSpacing = 5
        $0.minimumInteritemSpacing = 5
        $0.sectionInset = UIEdgeInsets.init(top: 19, left: 19, bottom: 19, right: 19)
        $0.backDelegate = self
    }
    private lazy var collView: UICollectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: colflow).then {
        $0.dataSource = self
        $0.delegate = self
        $0.showsVerticalScrollIndicator = false
        $0.showsHorizontalScrollIndicator = false
        $0.contentInset = UIEdgeInsets.init(top: 0, left: 0, bottom: 0, right: 0)
        $0.backgroundColor = .white
        $0.clipsToBounds = false
        $0.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "UICollectionViewCell")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        colflow.register(SuqareBackGroundReusableView.self, forDecorationViewOfKind: "SuqareBackGroundReusableView")
        colflow.itemSize = CGSize(width: 100, height: 100)
        self.view.addSubview(self.collView)
        self.collView.frame = self.view.bounds
    }
    
    
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 10
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 4
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "UICollectionViewCell", for: indexPath)
        cell.contentView.backgroundColor = .red
        return cell
    }

    func collbacklayout(_ collectionView: UICollectionView?, layout collectionViewLayout: MZFlowLayout_Background, insertForSectionAtIndex section: Int) -> UIEdgeInsets {
        return UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
    }
    
    func collbackDecorationViewKind(insertForSectionAtIndex section: Int) -> String? {
        if section == 0 {
            return "SuqareBackGroundReusableView"
        }
        return nil
    }
}

